package com.heima.article.controller.v1;


import com.heima.article.service.IApArticleService;
import com.heima.common.constants.ArticleConstants;
import com.heima.model.article.dtos.ArticleDto;
import com.heima.model.article.dtos.ArticleHomeDto;
import com.heima.model.common.dtos.ResponseResult;
import org.checkerframework.checker.units.qual.A;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import static com.heima.common.constants.ArticleConstants.LOADMORE;

/**
 * <p>
 * 文章信息表，存储已发布的文章 前端控制器
 * </p>
 *
 * @author lcz
 * @since 2024-11-17
 */
@RestController
@RequestMapping("/api/v1/article")
public class ApArticleController {

    @Autowired
    private IApArticleService iApArticleService;

    @PostMapping("load")
    public ResponseResult load(@RequestBody ArticleHomeDto dto) {
       return iApArticleService.load(dto, null);
    }

       @PostMapping("loadmore")
    public ResponseResult loadmore(@RequestBody ArticleHomeDto dto) {
       return iApArticleService.load(dto, ArticleConstants.LOADMORE);
    }

       @PostMapping("loadnew")
    public ResponseResult loadnew(@RequestBody ArticleHomeDto dto) {
       return iApArticleService.load(dto, ArticleConstants.LOADNEW);
    }

    /**
     * 文章保存
     * @param dto
     * @return
     */
    @PostMapping("save")
    public ResponseResult save(@RequestBody ArticleDto dto){
        Long articleId = iApArticleService.submit(dto);
        return ResponseResult.okResult(articleId);
    }
}
